/**
 * @Author your name
 * @Date 2021-03-05 10:00:36
 * @LastEditTime 2021-03-05 11:00:07
 * @LastEditors Please set LastEditors
 * @Description In User Settings Edit
 * @FilePath \fed-e-task-04-06\code\angular-demo\src\app\store\reducers\counte.reducer.ts
 */
// src\app\store\reducers\counte.reducer.ts
import { Action, createReducer, on } from '@ngrx/store';
import { decrement, increment } from '../actions/counter.actions';

// 状态名称
export const counteFeatureKey = 'counter';

// 状态类型接口
export interface State {
  count: number
}

// 初始状态
export const initialState: State = {
  count: 0
};

// 创建 reducer 函数
export const reducer = createReducer(
  initialState,
  on(increment, (state, action) => ({
    ...state,
    count: state.count + action.count
  })),
  on(decrement, state => ({
    ...state,
    count: state.count - 1
  }))
);

